import 'package:elephant_fish/page/index_new_rank_page.dart';
import 'package:elephant_fish/page/index_rank_home_page.dart';
import 'package:elephant_fish/page/rank_strategy_page.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class IndexRankPage extends StatefulWidget {
  const IndexRankPage({Key key}) : super(key: key);

  @override
  _IndexRankPageState createState() => _IndexRankPageState();
}

class _TabData {
  final Widget tab;
  final Widget body;

  _TabData({this.tab, this.body});
}

final _tabDataList = <_TabData>[
  _TabData(
      tab: Text('魅力榜'),
      body: IndexNewRankPage(
        rankName: '魅力榜',
      )),
  _TabData(
      tab: Text('贡献榜'),
      body: IndexNewRankPage(
        rankName: '贡献榜',
      )),
  _TabData(
      tab: Text('家族榜'),
      body: IndexNewRankPage(
        rankName: '家族榜',
      )),
];

class _IndexRankPageState extends State<IndexRankPage> {
  final tabBarList = _tabDataList.map((item) => item.tab).toList();
  final tabBarViewList = _tabDataList.map((item) => item.body).toList();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: DefaultTabController(
        length: tabBarList.length,
        child: Scaffold(
          appBar: AppBar(
            actions: [
              Align(
                alignment: Alignment.centerRight,
                child: Padding(padding: EdgeInsets.only(right: SizeUtil.px(56)),
                  child: InkWell(
                    child:Text('攻略',style: TextStyle(fontSize: SizeUtil.px(32),color: Color(0xfff3f3f3)),),
                    onTap: (){
                      Navigator.of(context).push( MaterialPageRoute(builder: (context)=>RankStrategyPage()));

                    },
                  )
                ),
              )

            ],
            leading:  GestureDetector(
              child: Icon(Icons.arrow_back_ios,size: SizeUtil.px(32),color: Color(0xfff3f3f3),),
              onTap: (){
                Navigator.pop(context);
              },
            ),
            backgroundColor: Color(0xff140c3c),
            title: Row(
              children: [
                Expanded(child: TabBar(
                  // isScrollable: true, //可滚动
                  // indicatorColor: Color(0xffff215d), //指示器的颜色
                  indicator: const BoxDecoration(),
                  labelColor: Color(0xfff3f3f3), //选中文字颜色
                  unselectedLabelColor: Color(0xff818181), //为选中文字颜色
                  isScrollable: true,
                  unselectedLabelStyle: TextStyle(
                    fontSize: SizeUtil.px(32),
                  ),
                  labelStyle: TextStyle(
                    fontSize: SizeUtil.px(36),
                  ),
                  // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
                  tabs: tabBarList,
                ),

                ),

              ],
            ),
          ),
          body:
          TabBarView(
              children: tabBarViewList
          ),
        ),
      ),
    );
  }
}
